package com.yufubao.strat.config;

import com.yufubao.model.properties.applet.search.ESProperties;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description es连接
 * @author zhangyiheng
 * @date 2024/9/6 00:02
 */
@Configuration
public class ElasticSearchConfig {
    @Autowired
    private ESProperties esProperties;

    /**
     * es8.x RestHighLevelClient被删除弃用，7.x无影响
     * @return
     */
    @Bean
    public RestHighLevelClient restHighLevelClient() {
        return new RestHighLevelClient(RestClient.builder(new HttpHost(esProperties.getHost(), esProperties.getPort(), esProperties.getScheme())));
    }
}
